package com.ude.pim.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ude.pim.common.R;
import com.ude.pim.entity.CaseSubUser;
import com.ude.pim.mapper.CaseSubUserMapper;
import com.ude.pim.service.CaseSubUserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ude.pim.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 专案子流程负责人表	信息：	专案子流程id	负责人id	积分	创建时间	创建人	更新时间	更新人 服务实现类
 * </p>
 *
 * @author yb
 * @since 2023-08-08
 */
@Service
public class CaseSubUserServiceImpl extends ServiceImpl<CaseSubUserMapper, CaseSubUser> implements CaseSubUserService {
    @Autowired
    private UserService userService;

    @Override
    //根据用户id获取姓名
    public String getNameById(Long id){
        return userService.getById(id).getName();
    }

    @Override
    public R<List<String>> countDirector(Long caseSubId) {
        LambdaQueryWrapper<CaseSubUser> lqw = new LambdaQueryWrapper<>();
        lqw.eq(CaseSubUser::getCaseSubId,caseSubId);
        List<CaseSubUser> list = this.list(lqw);
        List<String> directorNames = list.stream().map(s -> {
            Long userId = s.getUserId();
            String name = getNameById(userId);
            return name;
        }).collect(Collectors.toList());
        return R.success(directorNames);
    }
}
